package one.stand.service.impl;

import com.github.pagehelper.PageHelper;
import one.stand.model.InputDealMoneyModel;
import one.stand.model.ResultModel;
import one.stand.request.InputDealMoneyRequest;
import one.stand.response.InputDealMoneyResponse;
import one.stand.service.BaseService;
import one.stand.service.InputDealMoneyService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
/**
 * @author Administrator
 */
@Service
@Transactional
public class InputDealMoneyServiceImpl extends BaseService implements InputDealMoneyService {
    @Override
    public ResultModel<List<InputDealMoneyResponse>> getInputDealList(InputDealMoneyRequest request) {
        PageHelper.startPage(request.getPageNum(),request.getPageSize());
        InputDealMoneyModel inputDealMoneyModel=new InputDealMoneyModel();
        BeanUtils.copyProperties(request,inputDealMoneyModel);
        inputDealMoneyModel.setCompanyId(request.getCId().intValue());
        List<InputDealMoneyModel> moneyModelList=inputDealMoneyMapper.getInputDealList(inputDealMoneyModel);
        List<InputDealMoneyResponse> responseList=new ArrayList<>();
        moneyModelList.forEach(m->{
            InputDealMoneyResponse response=new InputDealMoneyResponse();
            BeanUtils.copyProperties(m,response);
            responseList.add(response);
        });
        return ResultModel.success(responseList);
    }

    @Override
    public ResultModel<InputDealMoneyResponse> selectDealDetail(InputDealMoneyRequest request) {
        InputDealMoneyModel inputDealMoneyModel=new InputDealMoneyModel();
        BeanUtils.copyProperties(request,inputDealMoneyModel);
        InputDealMoneyModel resultModel = inputDealMoneyMapper.selectDealDetail(inputDealMoneyModel);

        InputDealMoneyResponse response=new InputDealMoneyResponse();
        BeanUtils.copyProperties(resultModel,response);
        return ResultModel.success(response);
    }
}
